package com.szty.mod_jyzs.ui.pop

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.view.isVisible
import com.sjh.baseutils.loge
import com.szty.mod_jyzs.R
import razerdp.basepopup.BasePopupWindow

/**
 *@author : created by SunJH
 *时间：2021/8/9 000915
 *作用：提示保存视频的弹窗
 */
class HintSavePop(context: Context, saveVideo: (HintSavePop) -> Unit) : BasePopupWindow(context) {
    var showVideoInfo: TextView? = null
    var llUpload: LinearLayout? = null
    var llOrigin: LinearLayout? = null
    var pbUpload: ProgressBar? = null
    var tvProgress: TextView? = null

    var cancel:(()->Unit)? = null
    override fun onCreateContentView() = createPopupById(R.layout.jyzs_hint_save_pop)

    init {
        popupGravity = Gravity.CENTER
        showVideoInfo = findViewById(R.id.tv_show_video_info)
        findViewById<TextView>(R.id.tv_showInfo_cancel).setOnClickListener {
            dismiss()
            cancel?.invoke()
        }
        findViewById<TextView>(R.id.tv_show_info_save).setOnClickListener {
            saveVideo.invoke(this)
            switchShowPage(2)
        }
        llUpload=  findViewById(R.id.ll_upload)
        llOrigin=  findViewById(R.id.ll_origin)
        pbUpload=  findViewById(R.id.pb_upload)
        tvProgress=  findViewById(R.id.tv_progress)
    }

    /**
     * 切换弹窗界面显示
     * @param type 当前显示类型 1 原界面     2 进度条页面
     */
     fun switchShowPage(type: Int) {
        llOrigin?.isVisible = type == 1
        llUpload?.isVisible = type == 2
    }

    fun refUpLoadProgress(){
        tvProgress?.text = "0"
    }

    fun refurbishProgress(progress:Int){
        context.runOnUiThread {
            pbUpload?.progress = progress
            tvProgress?.text = progress.toString()
        }
    }
    fun showPopupWindow(info: String,cancel:()->Unit = {},isCanClickOutSidDismiss:Boolean = false) {
        setOutSideDismiss(isCanClickOutSidDismiss)
        this.cancel = cancel
        showVideoInfo?.text = info
        switchShowPage(1)
        super.showPopupWindow()
    }
}